package com.qbadroid;

import android.app.Activity;
import android.content.Intent;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.MediaPlayer;
import android.media.MediaRecorder.AudioSource;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;

public class ArticleActivity extends Activity {

	private TextView articleTitle;
	private TextView articleContent;
	private Button goToArticle;
	private Intent intent;
	
	private MediaPlayer mp;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.article);
		
		articleTitle = (TextView)findViewById(R.id.TextView08);
		articleContent = (TextView)findViewById(R.id.TextView09);
		goToArticle = (Button)findViewById(R.id.Button04);
		
		Animation alphaAnimation = AnimationUtils.loadAnimation(this, R.anim.myanim);
		articleContent.startAnimation(alphaAnimation);
		goToArticle.startAnimation(alphaAnimation);
		
		setVolumeControlStream(AudioManager.STREAM_MUSIC);
		if(mp != null)
		{
			mp.stop();
			mp.release();
		}
		
		mp = MediaPlayer.create(this, R.raw.monkey);
		mp.start();
		
		intent = getIntent();
		articleTitle.setText(intent.getStringExtra("articleTitle"));
		articleContent.setText(intent.getStringExtra("articleContent"));
		
		goToArticle.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent buttonIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(intent.getStringExtra("articleUrl")));
			startActivity(buttonIntent);
			}
		});
		
		//sprawdzenie dzialania AlertDialog
//		AlertDialog alert = new AlertDialog.Builder(this).create();
//		alert.setTitle("Alarm");
//		alert.setButton("OK", new DialogInterface.OnClickListener() {
//			
//			@Override
//			public void onClick(DialogInterface dialog, int which) {
//				// TODO Auto-generated method stub
//				
//			}
//		});
//		alert.show();
	}

	@Override
	protected void onPause() {
		if (mp != null) {
			mp.stop();
			mp.release();
		}
		super.onPause();
	}
}
